package com.huike.pmps.config.api;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;


@Configuration
@EnableSwagger2
//localhost:8081/swagger-ui.html
public class SwaggerConfig {
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .globalOperationParameters(getGlobalOperationParameters())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.huike.pmps.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("慧科教育")
                .contact(new Contact("慧科教育","",""))
                .description("生产管理平台接口文档")
                .version("1.0.0.0")
                .build();
    }
    private List<Parameter> getGlobalOperationParameters() {
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder parameterBuilder = new ParameterBuilder();
        //开发
        parameterBuilder.name("Authorization").description("用户授权token").modelRef(new ModelRef("string")).parameterType("header").required(true).defaultValue("Bearer 7c3f6ffc-9c31-4a2e-9eed-d61f172c7c71");
        //线上
        //parameterBuilder.name("Authorization").description("用户授权token").modelRef(new ModelRef("string")).parameterType("header").required(true).defaultValue("Bearer 86721290-14ee-46d8-9002-4b491704238c");
        pars.add(parameterBuilder.build());
        return pars;
    }
}
